﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using DevPhoneToolkitSample.Data;

namespace DevPhoneToolkitSample.Samples
{
    public partial class CheckPickerPageSample : PhoneApplicationPage
    {
        public CheckPickerPageSample()
        {
            InitializeComponent();
            var data = new ModelFruits[]
            {
                new ModelFruits{ Photo = new Uri("/Data/Fruits/apple_over.png", UriKind.Relative), Name = "Apple"},
                new ModelFruits{ Photo = new Uri("/Data/Fruits/bananas_over.png", UriKind.Relative), Name = "Banana"},
                new ModelFruits{ Photo = new Uri("/Data/Fruits/cherry_over.png", UriKind.Relative), Name = "Cherry"},
                new ModelFruits{ Photo = new Uri("/Data/Fruits/grapes_over.png", UriKind.Relative), Name = "Grape"},
                new ModelFruits{ Photo = new Uri("/Data/Fruits/pineapple_over.png", UriKind.Relative), Name = "Pineapple"},
                new ModelFruits{ Photo = new Uri("/Data/Fruits/strawberry_over.png", UriKind.Relative), Name = "Strawberry"},
            };
            Chkpk1.ItemsSource = data;
            Chkpk1.SelectedItems = new ModelFruits[] { data[0], data[2] };
        }

        private void ChkpgpickerSummaryConverter(object sender, DevPhone.Controls.SummaryConverterEventArgs e)
        {
            var result = e.SelectedItems.Cast<object>().Aggregate(string.Empty, (current, item) => current + (item + ";"));
            if (result.EndsWith(";", StringComparison.Ordinal))
            {
                result = result.Substring(0, result.Length - 1);
            }
            e.ValueConverted = result;
        }
    }
}